<?php
	if (isset($_GET['page'])) {
		$page = intval($_GET['page']);
	} else {
		$page = 1;
	}
	
	$url   = "index.php?controller=nxb&action=list";
	$limit = 10;
	
	$nxb       = new nxb;
	$total_rows = $nxb->total_num_rows();
	$total      = ceil($total_rows / $limit);
	
	$page = ($page <= 0) ? 1 : $page;
	$page = ($page > $total) ? $total : $page;
	
	$offset = ($page - 1) * $limit;
	
	$options = array(
		'limit' => $limit,
		'offset' => $offset,
		'order_by' => 'id DESC'
	);
	
	
	if (isset($_POST['pagecurrent'])) {
		$pagecurrent = $_POST['pagecurrent'];
		$pagecurrent = ($pagecurrent > $total) ? $total : $pagecurrent;
		$pagecurrent = ($pagecurrent <= 0) ? 1 : $pagecurrent;
		header("Location: $url&page=$pagecurrent");
	}
	
	
	$pagination = pagination($url, $page, $total);
	
	$list = $nxb->getbyoption($options);
	require("views/nxb/list_v.php");
?>